package com.swind.fast.modules.app.aerospace.capability.service.impl;

import com.swind.fast.modules.app.aerospace.capability.entity.AeroCapability;
import com.swind.fast.modules.app.aerospace.capability.entity.AeroCapabilityItem;
import com.swind.fast.modules.app.aerospace.capability.mapper.AeroCapabilityMapper;
import com.swind.fast.modules.app.aerospace.capability.service.IAeroCapabilityService;
import com.swind.fast.modules.app.aerospace.capability.service.IAeroCapabilityItemService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.swind.fast.common.system.vo.ItemModel;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Collectors;

/**
 * @Description: 项目
 * @Author: swind
 * @Date:   2021-11-20
 * @Version: V1.0
 */
@Service
public class AeroCapabilityServiceImpl extends ServiceImpl<AeroCapabilityMapper, AeroCapability> implements IAeroCapabilityService {

    @Autowired
    private IAeroCapabilityItemService aeroCapabilityItemService;


    @Override
    public Map<String, List<ItemModel>> queryAllCapabilityItems() {
        Map<String, List<ItemModel>> res = new HashMap<String, List<ItemModel>>();

        List<AeroCapability> list = this.list();

        LambdaQueryWrapper<AeroCapabilityItem> queryWrapper = new LambdaQueryWrapper<AeroCapabilityItem>();
        queryWrapper.orderByAsc(AeroCapabilityItem::getSortOrder);
        List<AeroCapabilityItem> aeroCapabilityItemList = aeroCapabilityItemService.list(queryWrapper);

        for (AeroCapability item : list) {
            List<ItemModel> capabilityItemList = aeroCapabilityItemList.stream().filter(s -> item.getId().equals(s.getCapId())).map(p -> {
                    return new ItemModel(p.getId(), p.getItemText());
                }
            ).collect(Collectors.toList());
            res.put(item.getCapCode(), capabilityItemList);
        }
        return res;
    }
}
